package com.study;

import com.study.bean.UserService;
import com.study.configuration.SpringConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/*测试声明式事务*/
public class TestDeclareTransaction {

    public static void main(String[] args) {
        //testXml();
        //testXmlAndAnnotation();
        testAnnotation();
    }

    /*Xml方式*/
    public static void testXml() {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-xml-annotation.xml");
        UserService userService = context.getBean(UserService.class);
        userService.testXmlDeclareTransaction();
    }

    /*Xml与Annotation混合方式*/
    public static void testXmlAndAnnotation() {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-xml-annotation.xml");
        UserService userService = context.getBean(UserService.class);
        userService.testAnnotationDeclareTransaction();
    }

    /*纯注解方式*/
    public static void testAnnotation() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfiguration.class);
        UserService userService = context.getBean(UserService.class);
        userService.testAnnotationDeclareTransaction();
    }

}
